﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using AsyncClient.DataRepositoryServiceRef;
using System.ServiceModel;

namespace AsyncClient
{
    class Program
    {
        private static readonly DataRepositoryServiceClient client = new DataRepositoryServiceClient();
        static void Main(string[] args)
        {
            try
            {
                client.BeginSetCabinets(new[] {CreateCabinet()}, SetCabinetsCompleted, null);
                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
            }

            Console.ReadLine();
        }

        private static void SetCabinetsCompleted(IAsyncResult ar)
        {
            client.EndSetCabinets(ar);
        }

        private static void GetCabinetsCompleted(IAsyncResult ar)
        {
            var c = client.EndGetCabinets(ar);
        }

        private static CabinetDto CreateCabinet()
        {
            var address1 = new AddressDto()
            {
                StreetName = "Bygmestervej",
                StreetNumber = 77,
                City = "København NV",
                ZipCode = 2400,
                Letter = "A",
                Floor = "St.",
                StairCasePosition = "Mf"
            };
            var entryHistory1 = new []
                                   {
                                       new HistoryEntryDto()
                                           {
                                               Comment = "Kommentar...",
                                               Date = new DateTime(2012, 4, 29),
                                               Reason = "Oprettet",
                                               User = "MMR"
                                           },
                                           new HistoryEntryDto()
                                               {
                                                   Comment = "Endnu en kommentar..",
                                                   Date = new DateTime(2012, 5, 1),
                                                   Reason = "Registreret forkert",
                                                   User = "MMR"
                                               }
                                   };
            var entry1 = new EntryDto()
            {
                Cable = "Blæsefiber 2 SM Emtelle",
                Cassette = 1,
                Tube = "Red",
                Fiber = "Blue",
                InnerTube = 1,
                InnerTubeId = "B3",
                FiberNumber = 2,
                LsseMb = "MB-39",
                Position = 3,
                Teletube = "TT",
                AddressDto = address1,
                EntryHistory = entryHistory1
            };

            var address2 = new AddressDto()
            {
                StreetName = "Bygmestervej",
                StreetNumber = 77,
                City = "København NV",
                ZipCode = 2400,
                Letter = "A",
                Floor = "1.",
                StairCasePosition = "Th"
            };
            var entryHistory2 = new []
                                   {
                                       new HistoryEntryDto()
                                           {
                                               Comment = "Kommentar...",
                                               Date = new DateTime(2012, 4, 28),
                                               Reason = "Rettet",
                                               User = "MMR"
                                           }
                                   };
            var entry2 = new EntryDto()
            {
                Cable = "Blæsefiber 2 SM Emtelle",
                Cassette = 1,
                Tube = "Orange",
                Fiber = "Blue",
                InnerTube = 1,
                InnerTubeId = "B3",
                FiberNumber = 2,
                LsseMb = "MB-39",
                Position = 3,
                Teletube = "TT",
                AddressDto = address2,
                EntryHistory = entryHistory2
            };

            var address3 = new AddressDto()
            {
                StreetName = "Bygmestervej",
                StreetNumber = 77,
                City = "København NV",
                ZipCode = 2400,
                Letter = " ",
                Floor = " ",
                StairCasePosition = " "
            };
            var entryHistory3 = new []
                                   {
                                       new HistoryEntryDto()
                                           {
                                               Comment = "Kommentar...",
                                               Date = new DateTime(2012, 4, 27),
                                               Reason = "Oprettet",
                                               User = "MMR"
                                           }
                                   };
            var entry3 = new EntryDto()
            {
                Cable = "Blæsefiber 8 SM Emtelle",
                Cassette = 1,
                Tube = "Orange",
                Fiber = "Red",
                InnerTube = 1,
                InnerTubeId = "B3",
                FiberNumber = 2,
                LsseMb = "MB-39",
                Position = 3,
                Teletube = "TT",
                AddressDto = address3,
                EntryHistory = entryHistory3
            };

            var cabinetAddress1 = new AddressDto() { StreetName = "Bygmestervej", StreetNumber = 77, 
                ZipCode = 2400, City = "København NV", Letter = "", Floor = "", StairCasePosition = ""};

            var cabinet1 = new CabinetDto()
            {
                CabinetId = "SK107 HAC",
                Latitude = 55.705142,
                Longitude = 12.536311,
                Entries = new [] { entry1, entry2 },
                AddressDto = cabinetAddress1
            };

            return cabinet1;
        }
    }
}
